﻿namespace BM.Tools.WebControls.MForm.Controls.Additions
{
    using System.ComponentModel;
    using System.Web.Script.Serialization;

    /// <summary>
    /// a class for returning the information about validity and the error text
    /// </summary>
    public class ServiceConstraintResponse
    {
        /// <summary>
        /// the isValid field
        /// </summary>
        private bool isValid = true;

        /// <summary>
        /// Gets or sets the ErrorText.
        /// </summary>
        /// <value>
        /// The error text.
        /// </value>
        public string ErrorText
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether the constraint is valid.
        /// </summary>
        /// <value>
        /// is the service constraint valid
        /// </value>
        [DefaultValue(true)]
        public bool IsValid
        {
            get
            {
                return isValid;
            }

            set
            {
                isValid = value;
            }
        }

        /// <summary>
        /// Creates the ServiceConstraintResponse object from its JSON string representation.
        /// </summary>
        /// <param name="text">
        /// The text representation.
        /// </param>
        /// <returns>
        /// ServiceConstraintResponse object.
        /// </returns>
        public static ServiceConstraintResponse FromString(string text)
        {
            return new JavaScriptSerializer().Deserialize<ServiceConstraintResponse>(text);
        }

        /// <summary>
        /// returns the serialized service constraint response
        /// </summary>
        /// <returns>
        /// the serialized service constraint response
        /// </returns>
        public override string ToString()
        {
            return new JavaScriptSerializer().Serialize(this);
        }
    }
}